package com.GB26875_3_2011;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.TimeUnit;

/**
 * @author 蒋仕国
 * @projectName GB26875_3_211
 * @ClassName App
 * @date 2025-01-13 13:28
 * @Description: TODO []
 */
//@SpringBootApplication
//@EnableGB26875
public class App {

//    public static void main(String[] args) {
//        SpringApplication.run(App.class, args);
//    }


    public static void main(String[] args) throws InterruptedException {
        // 定义两个 LocalDateTime 对象
        LocalDateTime endTime = LocalDateTime.parse("2025-01-20T18:00:00", DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        LocalDateTime startTime = LocalDateTime.now();
        while (startTime.isBefore(endTime)) {
            // 计算时间差
            Duration duration = Duration.between(startTime, endTime);
            // 获取小时、分钟和秒钟
            long totalMinutes = duration.toMinutes();
            long hours = totalMinutes / 60;
            long minutes = totalMinutes % 60;
            long seconds = duration.getSeconds() % 60;

            if (seconds % 2 == 0) {
                // 打印结果
                System.out.printf("\033[32m \t 时间差: \t %02d小时 \t %02d分钟 \t %02d秒钟 \033[0m \r\n", hours, minutes, seconds);
            } else {
                System.out.printf("\033[31m \t 时间差: \t %02d小时 \t %02d分钟 \t %02d秒钟 \033[0m \r\n", hours, minutes, seconds);
            }
            TimeUnit.MILLISECONDS.sleep(500);
            startTime = LocalDateTime.now();
        }
    }
}
